#include "datamodel.h"

DataModel::DataModel(QObject * parent) :
        QAbstractTableModel(parent), season(0)
{
    m_data.push_back(DataRow("June", 30));
    m_data.push_back(DataRow("July", 31));
    m_data.push_back(DataRow("August", 31));
    m_data.push_back(DataRow("September", 30));
    m_data.push_back(DataRow("October", 31));
    m_data.push_back(DataRow("November", 30));
    m_data.push_back(DataRow("December", 31));
    m_data.push_back(DataRow("January", 31));
    m_data.push_back(DataRow("February", 28));
    m_data.push_back(DataRow("March", 31));
    m_data.push_back(DataRow("April", 30));
    m_data.push_back(DataRow("May", 31));
}


int DataModel::rowCount(const QModelIndex &parent) const
{
    return season == 0 ?  m_data.size() : 3;
}

int DataModel::columnCount(const QModelIndex &parent) const
{
    return 2;
}

QVariant DataModel::data(const QModelIndex &index, int role) const
{
    if(role == Qt::DisplayRole && index.isValid())
    {
        if(season == 0)
        {
            if(index.column() == 0)
                return m_data[index.row()].month;
            else if(index.column() == 1)
                return m_data[index.row()].days;
        }
        else
        {
            if(index.column() == 0)
                return m_data[index.row() + 3*(season-1)].month;
            else if(index.column() == 1)
                return m_data[index.row() + 3*(season-1)].days;
        }

    }
    return QVariant();
}

void DataModel::filterChanged(int season)
{
    this->season = season;
    this->layoutChanged();
}

